package com.foo.designpattern.interpreter;

import java.util.HashMap;
import java.util.Map;

/**
 * com.foo.designpattern.interpreter
 * Created with IntelliJ IDEA.
 * Created by jiang on 2016-06-12 14:37.
 *
 * @Description 环境(Context)角色
 * 环境(Context)类定义出从变量到布尔值的一个映射
 */

public class Context {
    private Map<Variable, Boolean> map = new HashMap<Variable, Boolean>();

    public void assign(Variable var, boolean value) {
        map.put(var, new Boolean(value));
    }

    public boolean lookup(Variable var) throws IllegalArgumentException {
        Boolean value = map.get(var);
        if (value == null) {
            throw new IllegalArgumentException("value 值为空");
        }
        return value.booleanValue();
    }
}
